<?php

namespace Summer\Hjd\Http\Controllers;

use Illuminate\Routing\Controller;
use RLuders\JWTAuth\Classes\JWTAuth;
use Summer\Hjd\Models\MessageModel;
use Summer\Hub\Http\Controllers\Traits\ApiReturn;
use Input;
use Config;
use Db;
use Exception;
use System\Models\File as FileModel;


class MessageController extends Controller
{
    use ApiReturn;

    /**
     * 意见反馈
     * @param JWTAuth $auth
     * @param RgRecordRequest $request
     */
    public function create(JWTAuth $auth){
        if (!$user = $auth->user()) {
            return $this->apiError('登录失效,请重新登录');
        }
        $title=Input::get('title','');
        $content=Input::get('content','');
        $conimg_ids=Input::get('conimg_ids');
        if(empty($content)){
            return $this->apiError('请输入内容');
        }
        $message_table=new MessageModel();
        $message_table->title=$title;
        $message_table->content=$content;
        $message_table->from_uid=$user->id;
        $message_table->to_uid=0;
        $message_table->save();
        if($conimg_ids){
            foreach ($conimg_ids as $conimg_id){
                $file=FileModel::where('id',$conimg_id)->first();
                $message_table->conimg()->add($file);
            }
        }
        return $this->apiSuccess('操作成功');
    }
}
